package com.hollycrm.unicom.sheet.monitor.hibernate;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

import org.springframework.orm.hibernate.HibernateCallback;
import org.springframework.orm.hibernate.HibernateTemplate;
import org.springframework.orm.hibernate.support.HibernateDaoSupport;
import com.hollycrm.springframework.factory.DefaultBeanFactory;
import com.hollycrm.unicom.common.PageViewObject;
import com.hollycrm.unicom.sheet.BeanResource;
import com.hollycrm.unicom.sheet.Constants;
import com.hollycrm.unicom.sheet.domain.MainSheet;
import com.hollycrm.unicom.sheet.code.CodeManager;
import com.hollycrm.unicom.code.GeneralCode;
import com.hollycrm.unicom.sheet.domain.SmsSend;
import com.hollycrm.unicom.sheet.flow.SheetMove;
import com.hollycrm.unicom.sheet.monitor.MonitorDeptInfo;
import com.hollycrm.unicom.sheet.monitor.MonitorSheetJob;
import com.hollycrm.unicom.sheet.monitor.SheetMonitorItem;
import com.hollycrm.unicom.usersupport.DepartmentTreeViewObject;
import com.hollycrm.unicom.usersupport.User;
import com.hollycrm.unicom.usersupport.hibernate.HibernateUserSupportHelper;
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Query;
import net.sf.hibernate.Session;
import com.hollycrm.unicom.usersupport.Role;

public class HibernateMonitor_YC_AlertJobImpl
    extends HibernateMonitorSheetJob {
    public void checkAlerts() throws Exception {
      System.out.println(
          "Yellow_card -- the ScheduleJob and the pure bean method invoking !");

      final HibernateTemplate ht = getHibernateTemplate();
      ht.execute(new HibernateCallback() {
        List low_ls = new ArrayList();
        public Object doInHibernate(Session session) throws
            HibernateException {
          SimpleDateFormat df = (SimpleDateFormat) DefaultBeanFactory.
              getBean("dateFormatYear2second");
          String currentTime = df.format(new Date());

          Query qr1 = session.createQuery(RETRIEVE_TIMEOUT_Y_SHEETS);
          qr1.setString("currentTime", currentTime);
//          qr1.setString("alertFlag", Constants.SHEET_ALERT_TYPE_LOW);
          qr1.setString("alertFlag",Constants.SHEET_ALERT_TYPE_COMM);//added since 2005-11-15
          qr1.setString("sheetStage", Constants.SHEET_STAGE_NOSTAGE);
          qr1.setString("endStage", Constants.SHEET_STAGE_END);
          low_ls = qr1.list();

          monitorProcessAlert(session, low_ls, Constants.SHEET_ALERT_TYPE_LOW,
                       currentTime);
          return null;
        }
      });
    }
}

